<?
namespace pmvc\data\sql\sqlite3;

use PHPUnit_Framework_TestCase;
use Exception;

class SQLite3DataSourceTest
	extends PHPUnit_Framework_TestCase {

	public function testBasic() {
		if (!class_exists('SQLite3')) {
			// TODO: warn some how?
			return;
		}
		$dataSource = new SQLite3DataSource();
		$dataSource->filename = ":memory:";
		$dataSource->connect();
		$dataSource->update("create table test (id integer primary key autoincrement, name varchar(32))");
		$dataSource->update("insert into test (name) values ({0})", "brian");
		$lastId = $dataSource->lastInsertId();
		$this->assertTrue($lastId!=null);
		$obj = $dataSource->querySingle("select * from test where id={0}", $lastId);
		$this->assertNotNull($obj);
		$this->assertTrue($obj->id==$lastId);
		$this->assertTrue($obj->name=="brian");
		
		$obj = $dataSource->querySingleParams("select * from test where id={testing} or id={0}", Array(0=>"whatever", "testing"=> new \DateTime()));
		$this->assertFalse($obj);
	}

}

?>